package Codes_DAO;

import com.mva.common.StringUtils;
import com.mva.common.Displayable;
import com.mva.common.DataDictionaryConstants;

/*******************************************************************************
The <big><b>CodeType</b></big> class implements the <b>Displayable</b> &
<b>Cloneable</b> interfaces to create a <b>CodeType</b> object

@author z049984 - 1:33:38 PM - Aug 22, 2011

@version 1.2  
*******************************************************************************/
public class CodeType implements Displayable, Cloneable, DataDictionaryConstants
  {
   private String Sys;
   private String Sgmt;
   private String Desc;
   private int    Len;
   private char   YN_Num;
   private char   YN_UCase;

   /*******************************************************************************
	This constructor creates a new <b>CodeType</b> object with default values
   *******************************************************************************/
   public CodeType ()
	 {
	  this.Sys      = "MVA";
	  this.Sgmt     = "00";
	  this.Desc     = " ";
	  this.Len      =   2;
	  this.YN_Num   = 'N';
	  this.YN_UCase = 'N';
	 }

   /*******************************************************************************
	This constructor creates a new <b>CodeType</b> object with attribute values as
	defined by the provided parameters
	@param Sys A <b><i>String</i></b> variable
	@param Sgmt A <b><i>String</i></b> variable
	@param Desc A <b><i>String</i></b> variable
	@param Len An <b><i>int</i></b> variable
	@param YN_Num A <b><i>char</i></b> variable
	@param YN_UCase A <b><i>char</i></b> variable
   *******************************************************************************/
   public CodeType (String Sys, String Sgmt, String Desc, int Len, char YN_Num, char YN_UCase)
	 {
	  this.Sys      = Sys;
	  this.Sgmt     = Sgmt;
	  this.Desc     = Desc;
	  this.Len      = Len;
	  this.YN_Num   = YN_Num;
	  this.YN_UCase = YN_UCase;
	 }

   /*******************************************************************************
	Clones a current <b>CodeType</b> object to create a new one
	@return CodeType - A <b>CodeType</b> object
	@throws CloneNotSupportedException 
   *******************************************************************************/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Sys</b> attribute for the current
	<b>CodeType</b>	object
	@param Sys A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setSys (String Sys)
	 {
	  String tmpSys = Sys.toUpperCase();
	  this.Sys      = tmpSys;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Sys</b> attribute from the current
	<b>CodeType</b> object
	@return Sys - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getSys ()
	 {
	  return Sys;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Sgmt</b> attribute for the current
	<b>CodeType</b>	object
	@param Sgmt A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setSgmt (String Sgmt)
	 {
	  String tmpSgmt = Sgmt.toUpperCase();
	  this.Sgmt      = tmpSgmt;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Sgmt</b> attribute from the current
	<b>CodeType</b> object
	@return Sgmt - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getSgmt ()
	 {
	  return Sgmt;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Desc</b> attribute for the current
	<b>CodeType</b>	object
	@param Desc A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setDesc (String Desc)
	 {
	  String tmpDesc = Desc.trim();
	  this.Desc      = tmpDesc;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Desc</b> attribute from the current
	<b>CodeType</b> object
	@return Desc - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDesc ()
	 {
	  return Desc;
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Len</b> attribute for the current
	<b>CodeType</b>	object
	@param Len An <b><i>int</i></b> variable
   *******************************************************************************/
   public void setLen (int Len)
	 {
	  int tmpLen = Len;
	  if (tmpLen > 10)
	    {
		 tmpLen  = 10;  
	    }
	  else
	    {
		 if (tmpLen < 1)
		   {
			tmpLen = 1; 
		   }
	    }
	  this.Len   = tmpLen;
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Len</b> attribute from the current
	<b>CodeType</b> object
	@return Len - An <b><i>int</i></b> variable
   *******************************************************************************/
   public int getLen ()
	 {
	  return Len;
	 }
	
   /*******************************************************************************
	Sets the <b><i>char</i></b> <b>YN_Num</b> attribute for the current
	<b>CodeType</b>	object
	@param YN_Num A <b><i>char</i></b> variable
   *******************************************************************************/
   public void setYN_Num (char YN_Num)
	 {
	  char tmpYN  = YN_Num;
	  if (tmpYN == 'y' | tmpYN == 'Y')
	    {
		 tmpYN    = 'Y';  
	    }
	  else
	    {
		 tmpYN    = 'N'; 
	    }
	  this.YN_Num = tmpYN;
	 }

   /*******************************************************************************
	Retrieves the <b><i>char</i></b> <b>YN_Num</b> attribute from the current
	<b>CodeType</b> object
	@return YN_Num - A <b><i>char</i></b> variable
   *******************************************************************************/
   public int getYN_Num ()
	 {
	  return YN_Num;
	 }
	
   /*******************************************************************************
	Sets the <b><i>char</i></b> <b>YN_UCase</b> attribute for the current
	<b>CodeType</b>	object
	@param YN_UCase A <b><i>char</i></b> variable
   *******************************************************************************/
   public void setYN_UCase (char YN_UCase)
	 {
	  char tmpYN    = YN_UCase;
	  if (tmpYN == 'y' | tmpYN == 'Y')
	    {
		 tmpYN      = 'Y';  
	    }
	  else
	    {
		 tmpYN      = 'N'; 
	    }
	  this.YN_UCase = tmpYN;
	 }

   /*******************************************************************************
	Retrieves the <b><i>char</i></b> <b>YN_UCase</b> attribute from the current
	<b>CodeType</b> object
	@return YN_UCase - A <b><i>char</i></b> variable
   *******************************************************************************/
   public int getYN_UCase ()
	 {
	  return YN_UCase;
	 }

   /*******************************************************************************
	Determines whether or not all of the attribute values of one <b>CodeType</b>
	object are equal to all of the attribute values of a second <b>CodeType</b>
	object
	@param object A	<b>CodeType</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean equals (Object object)
     {
      if (object instanceof CodeType)
        {
         CodeType cdtyp2 = (CodeType) object;
         if (Sys.equals(cdtyp2.getSys())    &&
             Sgmt.equals(cdtyp2.getSgmt())  &&
             Desc.equals(cdtyp2.getDesc())  &&
             Len      == cdtyp2.getLen()    &&
             YN_Num   == cdtyp2.getYN_Num() &&
             YN_UCase == cdtyp2.getYN_UCase() )
         return true;
        }
      return false;
     }

   /*******************************************************************************
	Retrieves a one-line formatted list of the attribute values of the current
	<b>CodeType</b> object for use in a table display
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toTableString ()
	 {
	  String tmpLen = StringUtils.intToString(this.Len);
	  return StringUtils.padWithSpaces(this.Sys, Sys_LEN)   + "|" +
	         StringUtils.padWithSpaces(this.Sgmt, Sgmt_LEN) + "|" +
	         StringUtils.padWithSpaces(this.Desc, Desc_LEN) + "|" +
	         StringUtils.padWithSpaces(tmpLen, Len_LEN)     + "|" +
	         this.YN_Num                                    + "|" +
	         this.YN_UCase; 
	 }
   
   /*******************************************************************************
	Retrieves a formatted list of the attribute values of the current
	<b>CodeType</b> object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toString ()
	 {
	  return "System     : " + this.Sys      + "\n" +
	         "Segment    : " + this.Sgmt     + "\n" +
		     "Description: " + this.Desc     + "\n" +
		     "Length     : " + this.Len      + "\n" +
		     "Numeric?   : " + this.YN_Num   + "\n" +
		     "Uppercase? : " + this.YN_UCase + "\n";
	 }
   
   /*******************************************************************************
	Retrieves a formatted displayable list of the attribute values of the current
	<b>CodeType</b> object
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDisplayText ()
    {
	  return toString();
    }
  }
